import { currentDates } from '../../utils/util'
Page({
  data: {},
  onLoad() {
    this._getBaby()
  },
  async _getBaby() {
    let { code, data } = await wx.requestAsync({
      url: '/baby',
    })
    if (code == 0) {
      let list = data.map((item) => {
        item.birthday = currentDates(item.birthday * 1000, 1)
        return item
      })
      this.setData({
        list,
      })
    }
  },
  _tolinks({
    currentTarget: {
      dataset: { index },
    },
  }) {
    const { list } = this.data
    let only = JSON.stringify(list[index])
    wx.redirectTo({
      url: '/pages/babyonly/babyonly?only=' + only,
    })
  },
  _tolink() {
    wx.redirectTo({
      url: '/pages/babyonly/babyonly',
    })
  },
})
